﻿var req="";
var today = new Date();
function clearmsg() {
	var v1 = document.getElementById("allmsg");
	v1.value = "";
}

function creatRequest() {
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		
		try {
			XMLHttpReq = new ActiveXObject("Msxm12.XMLHTTP");
		} catch (e) {
			try {
				XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	}
	if (!req) {
		alert("ERROR");
	}

}



function reqPost() {
	var msg = document.getElementsByName("sendmsg")[0];
	if(msg.value!=""){
			var sendid = document.getElementsByName("userid")[0].value;
			var par = document.createElement("");
			var chi = document.createTextNode("时间："+today.toLocaleString()+
					"\r"+"我说："+msg.value+"\r"
					+"--------------------"+"\r");
			par.appendChild(chi);
			
			var v2 = document.getElementById("allmsg");
			v2.appendChild(par);
			creatRequest();
			var m =sendid+"●☆▲"+"1"+"●☆▲"+msg.value;
			var url = "SendMsgServlet";
	        
			req.open("post", url, true);
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

			req.send("msg="+m);
			msg.value="";
	}else{
		alert("不能发送空消息...");
	}
}

function getMeg(){
	creatRequest();
	var sendid = document.getElementsByName("userid")[0].value;
	if(sendid!= ""){
		
		var url = "ReceiveServlet?id="+sendid;
		req.open("get", url, true);
		req.onreadystatechange=callback;
		req.send(null);
	}
	var v = setTimeout("getMeg()",500);
}

function callback(){
	if(req.readyState==4){
		if(req.status==200){
			var rep = req.responseText;
			if(rep!=""){
				var par = document.createElement("");
				var chi = document.createTextNode(rep+"\r"+
						"***************"+"\r");
				par.appendChild(chi);
				var v2 = document.getElementById("allmsg");
				v2.appendChild(par);
				oTalkdiv.style.display='block';
			}
			
		}
	}
	
}


function register(){
	var username = document.getElementById("username");
    var password = document.getElementById("password");
	    var repassword = document.getElementById("repassword");
	    var email = document.getElementById("email");
	    var province = document.getElementById("province");
	    var aihao = document.getElementById("aihao").checked;
	    var qianming = document.getElementById("qianming");
	    if(username.value==""){
	            alert("请输入用户名")
	            username.focus();
	            return false;
       }else if(password.value==""){
            alert("请输入密码")
	            password.focus();
	            return false;
       }else if(repassword==""){
            alert("请确认密码输入")
            repassword.focus();
            return false;
       }else if(email.value==""){
            alert("请输入邮箱")
	            email.focus();
	            return false;
       }else if(province.value==""){
            alert("请选择省份");
            province.focus();
            return false;
       }else if(password.value!=repassword.value){
            alert("输入的密码不一致\n请确认密码");
            password.focus();
            return false;
       }else{
    	   document.forms[0].submit();
            return true;
       }
}



function repName(){
	
	if(req.readyState==4){
		if(req.status==200){
			var rep = req.responseText;
			if(rep!=""){
				alert(rep);
				document.getElementById("c").style.display = "none";
				var v2 = $('#check');
				v2.html(rep);
			}
		}
	}else{
		document.getElementById("c").style.display = "";
	}
	
}

function goToBuy(){
	
	
	
}
